<?php
Yii::import('ext.oauthLogin.qq.qqConnect',true);
Yii::import('ext.oauthLogin.sina.sinaWeibo',true);
class OauthController extends Controller
{
	public $layout='column1';

	/**
	 * @var CActiveRecord the currently loaded data model instance.
	 */
	private $_model;

	/**
	 * @return array action filters
	 */
	public function filters()
	{
		return array(
			'accessControl', // perform access control for CRUD operations
		);
	}

	/**
	 * Specifies the access control rules.
	 * This method is used by the 'accessControl' filter.
	 * @return array access control rules
	 */
	public function accessRules()
	{
		return array(
			array('allow',  // allow all users to access 'index' and 'view' actions.
				'actions'=>array('qq','sina'),
				'users'=>array('*'),
			),
			array('allow', // allow authenticated users to access all actions
				'users'=>array('@'),
			)
		);
	}


	/**
	 * get  qq user info
	 */
	public function actionQq()
	{
		$qqService = new qqConnectAuthV2(QQ_APPID,QQ_APPKEY);
		$_GET['redirect_uri']=QQ_CALLBACK_URL;
        $token = $qqService->getAccessToken('code',$_GET);
        $userinfo = $qqService->getUserInfo($token);
        echo  print_r ($userinfo);
	}
	/**
	 * get  qq user info
	 */
	public function actionSina()
	{
		 $weiboService = new SaeTOAuthV2(WB_AKEY,WB_SKEY);
		$_GET['redirect_uri']=WB_CALLBACK_URL;
        $token = $weiboService->getAccessToken('code',$_GET);
        $client= new SaeTClientV2(WB_AKEY,WB_SKEY,$token);
        $userinfo = $client->getUserShow($token);
        echo  print_r ($userinfo);
	}

}
